support/scripts/pkg-stats: make cells with many CVEs collapsible
PATCH 1/3 support/scripts/pkg-stats: make cells with many CVEs collapsible
Sometimes a package can have a lot of CVEs.
Rather than have the CVE cell make a really tall row (that means you have to scroll a bunch) this collapses the CVE cell to a fixed size scrollable element with a sticky button that lets you expand and collapse it.
If Javascript is enabled:
A stylesheet is generated and appended before content rendering, amending the cells style to have a fixed height and overflow.
Also, the expand/contract button is unhidden.
This means the CVE cells are rendered in a collapsed state instead of being rendered in an expanded state and then slamming shut.
This avoids a "flash" and *helps* (vertically at least) manage CLS (cumulative layout shift).
see: https://web.dev/cls/
If Javascript is disabled:
The cells stay fully open and the expand/contract button stays hidden.
--- support/scripts/pkg-stats | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-)
support/scripts/pkg-stats +36 -2
@@ -747,6 +747,14 @@ html_header = """ const triangleUp = String.fromCodePoint(32, 9652); const triangleDown = String.fromCodePoint(32, 9662); var lastColumnName = false; +const styleElement = document.createElement('style'); +document.head.insertAdjacentElement("afterend", styleElement); +const styleSheet = styleElement.sheet; +const collapseRule = ".collapse{ height: 200px; overflow: hidden scroll;}" +const buttonRule = ".see-more{ display: block;}" + +styleSheet.insertRule(collapseRule); +styleSheet.insertRule(buttonRule); function sortGrid(sortLabel){ let i = 0;
@@ -759,7 +767,6 @@ function sortGrid(sortLabel){ lastStyle.disable = true; lastStyle.remove(); }; - const styleElement = document.createElement('style'); styleElement.id = "sort-css"; document.head.appendChild(styleElement); const styleSheet = styleElement.sheet;
@@ -809,16 +816,37 @@ function sortGrid(sortLabel){ let rule = "." + listing[0] + " { grid-row: " + i + "; }"; styleSheet.insertRule(rule); }); + styleSheet.insertRule(collapseRule); + styleSheet.insertRule(buttonRule); +}; + +function expandField(fieldId){ + const field = document.getElementById(fieldId); + const fieldText = field.firstElementChild.innerText; + const fieldTotal = fieldText.split(' ')[2]; + + if (fieldText == "see all " + fieldTotal + triangleDown){ + field.firstElementChild.innerText = "see less " + fieldTotal + triangleUp; + field.style.height = "auto"; + } else { + field.firstElementChild.innerText = "see all " + fieldTotal + triangleDown; + field.style.height = "200px"; + } }; </script> <style> -.label { +.see-more{ + display: none; +} + +.label, .see-more { position: sticky; top: 1px; } .label{ + z-index: 1; background: white; padding: 10px 2px 10px 2px; }
@@ -1029,6 +1057,8 @@ def dump_html_pkg(f, pkg): data_field_id = f'cves__{pkg_css_class}' div_class = ["centered cves data"] div_class.append(f'_{pkg_css_class}') + if len(pkg.cves) > 10: + div_class.append("collapse") if pkg.is_status_ok("cve"): div_class.append("cve-ok") elif pkg.is_status_error("cve"):
@@ -1038,6 +1068,10 @@ def dump_html_pkg(f, pkg): else: div_class.append("cve-unknown") f.write(f' <div id=\"{data_field_id}\" class=\"{" ".join(div_class)}\">\n') + if len(pkg.cves) > 10: + cve_total = len(pkg.cves) + 1 + f.write(f' <div onclick=\"expandField(\'{data_field_id}\')\" \ + class=\"see-more centered cve_ignored\">see all ({cve_total}) ▾</div>\n') if pkg.is_status_error("cve"): for cve in pkg.cves: f.write(" <a href=\"https://security-tracker.debian.org/tracker/%s\">%s</a><br/>\n" % (cve, cve))
Signature · 17 lines
2.34.1 From cbb01a5a28346617aa2fbf17479fb5aed1d2b0c0 Mon Sep 17 00:00:00 2001 From: Sen Hastings <[email protected]> Date: Thu, 28 Jul 2022 15:05:34 -0500 Subject: [PATCH 1/2] support/scripts/pkg-stats: make cells with many CVEs collapseable _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH 2/3 support/scripts/pkg-stats: adjust column widths
This adjusts the column widths, mostly for asthetics/legibility.
It is primarily for chrome based browsers, which like to linebreak on explicit hyphens, meaning every CVE takes multiple lines.
see: https://github.com/w3c/csswg-drafts/issues/3434
--- support/scripts/pkg-stats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
support/scripts/pkg-stats +1 -1
@@ -853,7 +853,7 @@ function expandField(fieldId){ #package-grid, #results-grid { display: grid; grid-gap: 2px; - grid-template-columns: 1fr repeat(12, min-content); + grid-template-columns: max-content repeat(5, min-content) 20ch repeat(3, max-content) repeat(2, 20ch) auto; } #results-grid { grid-template-columns: 3fr 1fr;
Signature · 6 lines
2.34.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Re: [Buildroot] [PATCH 2/3] support/scripts/pkg-stats: adjust column widths
Quoted 8 lines · On Thu, 28 Jul 2022 18:23:56 -0500 Sen Hastings <[email protected]> wrote:
This adjusts the column widths, mostly for asthetics/legibility.
It is primarily for chrome based browsers, which like to linebreak on explicit hyphens, meaning every CVE takes multiple lines.
see: https://github.com/w3c/csswg-drafts/issues/3434
Signed-off-by Sen Hastings <[email protected]>
This doesn't behave extremely well here as it prevents wrapping of the package .mk file path in the first column, making this first column larger than it was. I guess wrapping on "/" would be ideally for this first column.
Here the table continues to exceed the width of my large browser window (with or without this patch), which is not very nice :-/
Thomas
Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin Embedded Linux and Kernel engineering and training https://bootlin.com _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Re: [Buildroot] [PATCH 2/3] support/scripts/pkg-stats: adjust column widths
Hi Sen,
Quoted 12 lines · Thomas Petazzoni via buildroot
Quoted 8 lines · On Thu, 28 Jul 2022 18:23:56 -0500 Sen Hastings <[email protected]> wrote:
This adjusts the column widths, mostly for asthetics/legibility.
It is primarily for chrome based browsers, which like to linebreak on explicit hyphens, meaning every CVE takes multiple lines.
see: https://github.com/w3c/csswg-drafts/issues/3434
Signed-off-by Sen Hastings <[email protected]>
Quoted 7 lines
This doesn't behave extremely well here as it prevents wrapping of the package .mk file path in the first column, making this first column larger than it was. I guess wrapping on "/" would be ideally for this first column.
Here the table continues to exceed the width of my large browser window (with or without this patch), which is not very nice :-/
Since pkg-stats takes a pretty long time to run, it would be nice if you could
publish the output of pkg-stats (with no .config) somewhere so we can look at it directly and notice these things easier.
Regards,
Arnout
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Re: [Buildroot] [PATCH 2/3] support/scripts/pkg-stats: adjust column widths
Quoted 20 lines · Arnout Vandecappelle
Hi Sen,
Quoted 17 lines · Thomas Petazzoni via buildroot
Quoted 8 lines · On Thu, 28 Jul 2022 18:23:56 -0500 Sen Hastings <[email protected]> wrote:
This adjusts the column widths, mostly for asthetics/legibility.
It is primarily for chrome based browsers, which like to linebreak on explicit hyphens, meaning every CVE takes multiple lines.
see: https://github.com/w3c/csswg-drafts/issues/3434
Signed-off-by Sen Hastings <[email protected]>This doesn't behave extremely well here as it prevents wrapping of the package .mk file path in the first column, making this first column larger than it was. I guess wrapping on "/" would be ideally for this first column.
Quoted 6 lines
Quoted 2 lines
Here the table continues to exceed the width of my large browser window (with or without this patch), which is not very nice :-/
Since pkg-stats takes a pretty long time to run, it would be nice if you could publish the output of pkg-stats (with no .config) somewhere so we can look at it directly and notice these things easier.>
Yeah, these weird edge cases only crop up when you build all the packages... which requires building all the packages.
My usual dev cycle is to pull master.html, edit the js in situ and then move it back into the pkg-stats script. I usually only run pkg-stats against a fairly simple defconfig like pc_x86_64_efi or my own personal project. I guess I should do a full build of master weekly, and perhaps a nightly run of pkg-stats, then host the html somewhere. And perhaps I should look into parsing the json output into html...
Sincerely,
Sen H.
Quoted 3 lines
Regards,
Arnout
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Re: [Buildroot] [PATCH 2/3] support/scripts/pkg-stats: adjust column widths
Quoted 5 lines · On Tue, 2 Aug 2022 15:30:06 -0500 Sen Hastings <[email protected]> wrote:
Quoted 3 lines
Since pkg-stats takes a pretty long time to run, it would be nice if you could publish the output of pkg-stats (with no .config) somewhere so we can look at it directly and notice these things easier.>
Yeah, these weird edge cases only crop up when you build all the packages... which requires building all the packages.
No, you don't. Just run it manually:
./support/scripts/pkg-stats --html foo.html --nvd-path ~/path/to/somewhere/
This will use pkg-stats without the -c option, and therefore pkg-stats will handle all packages rather than just the ones selected in your configuration.
Thomas
Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin Embedded Linux and Kernel engineering and training https://bootlin.com _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH 3/3 support/scripts/pkg-stats: re-implement the sortable_hint
In reply to Sen HastingsThis attempts to re-implement the "sortable_hint" feature without relying on words. The column headers and CVE expand/contract buttons change color and cursor style on hover.
If Javascript is enabled:
Just like [PATCH 1/3] more rules are applied to the generated stylesheet before content is loaded.
If Javascript is disabled:
The headers stay pearly white. :-)
--- support/scripts/pkg-stats | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)
support/scripts/pkg-stats +7 -13
@@ -750,11 +750,13 @@ var lastColumnName = false; const styleElement = document.createElement('style'); document.head.insertAdjacentElement("afterend", styleElement); const styleSheet = styleElement.sheet; -const collapseRule = ".collapse{ height: 200px; overflow: hidden scroll;}" -const buttonRule = ".see-more{ display: block;}" +addedCSSRules = [ +".collapse{ height: 200px; overflow: hidden scroll;}", +".see-more{ display: block;}", +".label:hover,.see-more:hover { cursor: pointer; background: #d2ffc4;}" +]; -styleSheet.insertRule(collapseRule); -styleSheet.insertRule(buttonRule); +addedCSSRules.forEach(rule => styleSheet.insertRule(rule)); function sortGrid(sortLabel){ let i = 0;
@@ -816,8 +818,7 @@ function sortGrid(sortLabel){ let rule = "." + listing[0] + " { grid-row: " + i + "; }"; styleSheet.insertRule(rule); }); - styleSheet.insertRule(collapseRule); - styleSheet.insertRule(buttonRule); + addedCSSRules.forEach(rule => styleSheet.insertRule(rule)); }; function expandField(fieldId){
@@ -887,17 +888,10 @@ function expandField(fieldId){ <a href=\"#results\">Results</a><br/> -<p id=\"sortable_hint\"></p> """ # noqa - tabs and spaces html_footer = """ -<script> -if (typeof sortGrid === "function") { - document.getElementById("sortable_hint").innerHTML = - "hint: the table can be sorted by clicking the column headers" -} -</script> </body> </html> """
Signature · 6 lines
2.34.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Thomas Petazzoni via buildroot
AppliedRe: [Buildroot] [PATCH 3/3] support/scripts/pkg-stats: re-implement the sortable_hint
Quoted 9 lines · On Thu, 28 Jul 2022 18:23:57 -0500 Sen Hastings <[email protected]> wrote:
This attempts to re-implement the "
sortable_hint" feature without relying on words. The column headers and CVE expand/contract buttons change color and cursor style on hover.If Javascript is enabled:
Just like [PATCH 1/3] more rules are applied to the generated stylesheet before content is loaded.
Quoted 8 lines
If Javascript is disabled:
The headers stay pearly white. :-)
Signed-off-by Sen Hastings <[email protected]>--- support/scripts/pkg-stats | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)
Applied to master, thanks.
Thomas
Signature · 7 lines
Thomas Petazzoni, CTO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Thomas Petazzoni via buildroot
AppliedQuoted 22 lines · On Thu, 28 Jul 2022 18:23:55 -0500 Sen Hastings <[email protected]> wrote:
Sometimes a package can have a lot of CVEs.
Rather than have the CVE cell make a really tall row (that means you have to scroll a bunch) this collapses the CVE cell to a fixed size scrollable element with a sticky button that lets you expand and collapse it.If Javascript is enabled:
A stylesheet is generated and appended before content rendering, amending the cells style to have a fixed height and overflow.
Also, the expand/contract button is unhidden.
This means the CVE cells are rendered in a collapsed state instead of being rendered in an expanded state and then slamming shut.
This avoids a "flash" and *helps* (vertically at least) manage CLS (cumulative layout shift).
see: https://web.dev/cls/
Quoted 8 lines
If Javascript is disabled:
The cells stay fully open and the expand/contract button stays hidden.
Signed-off-by Sen Hastings <[email protected]>--- support/scripts/pkg-stats | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-)
Applied to master, thanks.
Thomas
Signature · 7 lines
Thomas Petazzoni, CTO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot